package org.example.springwebmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.HashMap;

@RequestMapping("/response")
//@RestController //使用 @RestController 注解的类会被 Spring 容器作为控制器类进行管理。

@Controller
public class ResponseController {

    @RequestMapping("/index")
    public String index(){
        return "/index.html";
    }

    @ResponseBody
    @RequestMapping("/indexData")
    public String indexData(){
        return "返回数据";
    }

    @ResponseBody
    @RequestMapping(value = "/indexData2")
    public String indexData2(){
        return "<h1>Java 666</h1>"; // 也可以返回页面
    }

//    Json 格式
    @ResponseBody
    @RequestMapping("/getMap")
    public HashMap<String, String> getMap(){
        HashMap<String,String> map = new HashMap<>();
        map.put("java","666");
        map.put("python","999");
        return map;
    }

//      通过设置 produces属性的值, 设置响应的报头Content-Type
    @ResponseBody
    @RequestMapping(value = "/Content-Type",produces = "application/json")
    public String ct(){
        return "{\"success\":true}";
    }
}
